#include "MainScene.h"
#include "GameScene.h"


USING_NS_CC;

Scene* MainScene::createScene()
{
    auto scene = Scene::create();
    
	auto layer = MainScene::create();

    scene->addChild(layer);

    return scene;

	CCLOG("CREATESCENErrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr");
}

// on "init" you need to initialize your instance
bool MainScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();


	main();

	return true;
}
void MainScene::main()
{
	CCLOG("mainmainmiainmania");
	//Create main title background and buttons 
	Sprite* _mainBg = Sprite::create("main/title.png");
	_mainBg->setAnchorPoint(Point::ZERO);
	_mainBg->setPosition(Point::ZERO);
	_mainBg->setScale(1.5f);
	this->addChild(_mainBg);

	MenuItemImage* _start = MenuItemImage::create("main/startbutton.png", "main/startpressed.png", CC_CALLBACK_0(MainScene::toGame, this));
	_start->setPosition(Point(540,1000));
	//MenuItemImage* _rank = MenuItemImage::create("rankbutton.png","rankpressed.png", CC_CALLBACK_0(toRank,this));
	//MenuItemImage* _achivement = MenuItemImage::create("achivementbutton.png","achivementpressed.png",CC_CALLBACK_0(toAchivement,this));
	
	MenuItemImage* resetButton = MenuItemImage::create(
		"main/startbutton.png",
		"main/startbutton.png",
		CC_CALLBACK_0(MainScene::resetUserDefault, this));
	resetButton->setAnchorPoint(Point(0, 0));
	resetButton->setPosition(Point(50, 50));
	resetButton->setOpacity(50);


	Menu* _mainButton = Menu::create(_start, resetButton, NULL);
	_mainButton->setAnchorPoint(Point::ZERO);
	_mainButton->setPosition(Point::ZERO);
	this->addChild(_mainButton);
}

void MainScene::toGame()
{
	TransitionFadeBL* _toStart = TransitionFadeBL::create(1.0f, GameScene::createScene());
	Director::getInstance()->replaceScene(_toStart);
}
void MainScene::toRank()
{

}
void MainScene::toAchivement()
{

}


void MainScene::resetUserDefault() {

	UserDefault::getInstance()->setFloatForKey("currentStg", 1);
	UserDefault::getInstance()->setFloatForKey("exp", 0);
	UserDefault::getInstance()->flush();

}